package com.zero2oneblog.controller;

import com.zero2oneblog.service.IApiAccessStatisticsService;
import com.zero2oneblog.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liangjiu
 * @since 2024-01-04
 */
//@Controller
//@RequestMapping("/zero2oneblog/apiAccessStatistics")
@RestController
public class ApiAccessStatisticsController {

    private final IApiAccessStatisticsService iApiAccessStatisticsService;

    @Autowired
    public ApiAccessStatisticsController(IApiAccessStatisticsService apiAccessStatisticsService) {
        this.iApiAccessStatisticsService = apiAccessStatisticsService;
    }

//    @Autowired  //循环依赖
//    private IApiAccessStatisticsService iApiAccessStatisticsService;

    @GetMapping("/public/apicount")
    public ResponseVO<String> exampleApi() {
        // 具体业务逻辑
        iApiAccessStatisticsService.incrementAccessCountByDataBase("/public/apicount");
        return ResponseVO.ok("Example API Response");
    }

    @GetMapping("/public/apicountbytask")
    public ResponseVO<String> exampleApi2() {
        // 具体业务逻辑
        iApiAccessStatisticsService.incrementAccessCountByAtomicTask("/public/apicountbytask");
        return ResponseVO.ok("Example API Response task");
    }


    @GetMapping("/public/apicountbyredis")
    public ResponseVO<String> exampleApi3() {
        // 具体业务逻辑
        iApiAccessStatisticsService.incrementAccessCountByRedis("/public/apicountbyredis");
        return ResponseVO.ok("Example API Response task redis");
    }

}
